<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    var singleton = (function(){
        function pinks(){
            this.dom = null
            this.color= 0
            this.run = function(){}
        }
        var insts = null
        return{
            getInstance(){
                // 方式一=======================
                // if(insts){
                //     return insts
                // }else{
                //     return insts = new pinks()
                // }
                // 方式二=========================
                // return insts?insts:(insts = new pinks)

                // 方式三==========================
                return insts || (insts = new pinks)
            }
        }
    })()
    var a = singleton.getInstance()
    var b = singleton.getInstance()
    var c = singleton.getInstance()
    console.log(a,b,c);
    console.log(a==b);
    console.log(a==c);
    console.log(b==c);
</script>